/****************************************************************************
 *
 * Copyright 2020 NXP.
 *
 * NXP Confidential. 
 * 
 * This software is owned or controlled by NXP and may only be used strictly 
 * in accordance with the applicable license terms.  
 * By expressly accepting such terms or by downloading, installing, activating 
 * and/or otherwise using the software, you are agreeing that you have read, 
 * and that you agree to comply with and are bound by, such license terms.  
 * If you do not agree to be bound by the applicable license terms, 
 * then you may not retain, install, activate or otherwise use the software. 
 * 
 *
 ****************************************************************************/


/*****************************************************************************
 *
 * MODULE:             ZPS NWK
 *
 * COMPONENT:          zps_nwk_sap.h
 *
 * DESCRIPTION:        ZPS NWK SAP interface
 *
 *****************************************************************************/

/**
 * @defgroup g_zps_nwk_sap ZPS NWK layer Service Access Point (SAP)
 */

/**
 * @defgroup g_zps_nwk_sap_pib PIB parameters
 *
 * Parameters associated with setting or getting PIB values
 * @ingroup g_zps_nwk_sap
 */

/**
 * @defgroup g_zps_nwk_sap_addr Addressing parameters
 *
 * Parameters associated with addressing
 * @ingroup g_zps_nwk_sap
 */

/**
 * @defgroup g_zps_nwk_sap_pdu PDU Framing parameters
 *
 * Parameters associated with PDU framing
 * @ingroup g_zps_nwk_sap
 */

/**
 * @defgroup g_zps_nwk_sap_sec Security parameters
 *
 * Parameters associated with security
 * @ingroup g_zps_nwk_sap
 */

/**
 * @defgroup g_zps_nwk_sap_scan Scanning parameters
 *
 * Parameters associated with scanning
 * @ingroup g_zps_nwk_sap
 */

/**
 * @defgroup g_zps_nwk_sap_nlme ZPS NWK SAP sublayer management entity (NLME)
 *
 * The NLME SAP API provides calls to conforming to the NLME SAP in [1]
 * @ingroup g_zps_nwk_sap
 */

/**
 * @defgroup g_zps_nwk_sap_nlde ZPS NWK SAP common part sublayer (NLDE)
 *
 * The NLDE SAP API provides calls to conforming to the NLDE SAP in [1]
 * @ingroup g_zps_nwk_sap
 */

/**
 * @defgroup g_zps_nwk_sap_vs Vendor-specific interface
 *
 * The vendor-specific SAP API provides calls which are in addition to those specified in the 802.15.4
 * specification. They are currently handled as additions to the NLME SAP interface.
 * @ingroup g_zps_nwk_sap
 */

/**
 * @mainpage Application Programmer's Interface<br>ZigBee Protocol Stack Service Access Point
 *
 * @section p_ZPS_NWK_SAP_intro Introduction
 * The ZigBee Protocol Stack Network Layer (ZPS NWK) Service Access Point (SAP) Application Programmer's Interface (API)
  provides the interface to the top of the ZPS Network layer required by higher layer in the application programming.
 * The next layer up is typically the ZigBee Protocol Stack Network Layer ZDO/APS (ZPS APL).
 *
 * @section page_ZPS_NWK_SAP_infra Infrastructure
 * There is an additional infrastructure interface to allow construction and destruction of the MAC and
 * Transceiver objects and to allow hooking up of low-level interrupts generated by the Transceiver to the MAC
 * event handlers.
 * - ZPS NWK infrastructure API: See @link grp_zps_nwk ZPS NWK pages@endlink
 *
 * @section page_ZPS_NWK_SAP_categories Categories within ZPS NWK SAP
 * - NLDE SAP API: See @link g_zps_nwk_sap_nlde NLDE SAP pages@endlink
 * - NLME SAP API: See @link g_zps_nwk_sap_nlme NLME SAP pages@endlink
 * - Vendor-specific SAP API: See @link g_zps_nwk_sap_vs Vendor-specific pages@endlink
 *
 * @section page_disclaimer Disclaimer
 * This is the first release of the automatically-generated API document which assumes availability of all source
 * files and is subject to change. Future versions may require a different infrastructure configuration using opaque pointers but the SAP API
 * calls will essentially be the same.
 */

#ifndef _zps_nwk_sap_h_
#define _zps_nwk_sap_h_

#ifdef __cplusplus
extern "C" {
#endif

/***********************/
/**** INCLUDE FILES ****/
/***********************/

#include "jendefs.h"
#include <zps_nwk_config.h>
#include <pdum_nwk.h>

/************************/
/**** MACROS/DEFINES ****/
/************************/

/* Literals */

/**** Bit widths ****/

#ifndef BIT_W_1
#define BIT_W_1     0x1
#define BIT_W_2     0x3
#define BIT_W_3     0x7
#define BIT_W_4     0xF
#define BIT_W_5     0x1F
#define BIT_W_6     0x3F
#define BIT_W_7     0x7F
#define BIT_W_8     0xFF
#endif

/**
 * @name PHY constants
 * @ingroup g_zps_nwk_sap
 * PHY constants 'used' by the MAC
 * @{
 */
/** Maximum PHY packet (PDU) size */
#define ZPS_NWK_MAX_PHY_PKT_SIZE            127
/** PHY turnaround time */
#define ZPS_NWK_PHY_TURNAROUND_TIME         12
/* @} */

/**
 * @name Address sizes
 * @ingroup g_zps_nwk_sap_addr
 * Sizes of address fields in SAP structures
 * @{
 */
/** PAN ID field size in octets */
#define ZPS_NWK_PAN_ID_LEN                  2
/** Address field size in octets */
#define ZPS_NWK_ADDR_LEN                    2
/** IEEE Address field size in octets */
#define ZPS_NWK_IEEE_ADDR_LEN               8
/** IEEE Address field size in octets */
#define ZPS_NWK_EXT_PAN_ID_LEN              8
/** ZPS NWK always uses addres mode 2 */
#define ZPS_NWK_MAC_ADDR_MODE               2


 /** ZPS MAC Extended addressing mode */

#define ZPS_MAC_ADDR_MODE_SHORT             2
#define ZPS_MAC_ADDR_MODE_EXTENDED      	3



/* @} */

/**
 * @name Frame overheads
 * @ingroup g_zps_nwk_sap_pdu
 * Header size overheads for frames
 * @{
 */
/** Minimum Data Frame overhead */
#define ZPS_NWK_MIN_DATA_FRM_OVERHEAD       9
/** Maximum Data Frame overhead */
#define ZPS_NWK_MAX_DATA_FRM_OVERHEAD       25
/** Minimum Beacon Frame overhead */
#define ZPS_NWK_MIN_BEACON_FRM_OVERHEAD     9
/** Maximum Beacon Frame overhead */
#define ZPS_NWK_MAX_BEACON_FRM_OVERHEAD     15
/* @} */

/**
 * @name Joining capabilities
 * @ingroup g_zps_nwk_sap_join
 * Capability bitmaps used in joining.
 * Bizarrely defined at the MAC layer even though
 * it cares little about them
 * @{
 */
/** Power source */
#define ZPS_NWK_JOIN_DEVICE_MASK            0x02
/** Power source */
#define ZPS_NWK_JOIN_POWER_SOURCE_MASK      0x04
/** Rx on when idle */
#define ZPS_NWK_JOIN_RX_ON_WHEN_IDLE_MASK   0x08
/** Security capable */
#define ZPS_NWK_JOIN_SEC_CAPABLE_MASK       0x40
/* @} */

/**
 * @name Payload maxima
 * @ingroup g_zps_nwk_sap_pdu
 * Maximum size of payloads
 * @{
 */
/** Maximum Data Frame payload */
#define ZPS_NWK_MAX_DATA_PAYLOAD_LEN      (ZPS_NWK_MAX_PHY_PKT_SIZE - ZPS_NWK_MIN_DATA_FRM_OVERHEAD)
/** Maximum Beacon Frame payload */
#define ZPS_NWK_MAX_BEACON_PAYLOAD_LEN    (ZPS_NWK_MAX_PHY_PKT_SIZE - ZPS_NWK_MIN_BEACON_FRM_OVERHEAD)
/* @} */

/**
 * Network protocol ID
 */
#define ZPS_NWK_PROTOCOL_ID                 0

/**
 * Network protocol version
 * @note 053474r17: Version 2 (nwkcProtocolVersion)
 */
#define ZPS_NWK_PROTOCOL_VER                2
#define ZPS_NWK_PROTOCOL_GREEN_POWER_VER     3
/**
 * Stack profile (feature set) IDs
 */
#define ZPS_NWK_PROTOCOL_ZB_FS_ID           1
#define ZPS_NWK_PROTOCOL_ZB_PRO_FS_ID       2

/**
 * @name NIB constants
 * @ingroup g_zps_nwk_sap_nib
 * NIB constant values (nwkc)
 * @{
 */
/** @a nwkcMaxDepth: Maximum no. of hops a device can be from coordinator (tree depth) */
#define ZPS_NWK_NWKC_MAX_DEPTH              7
/* @} */

/**
 * @name Scan constants
 * @ingroup g_zps_nwk_sap_scan
 * Scan constant values not in PIB
 * @note ZPS_NWK_MAX_DISC_NWK_DESCRS is configurable
 * @{
 */
/** Maximum number of scan channel (2.4GHz) */
//#define ZPS_NWK_MAX_SCAN_CHANNELS           16
/** Maximum number of network descriptors in record */
#define ZPS_NWK_MAX_DISC_NWK_DESCRS         12


#define ZPS_NWK_MAX_ED_RESULTS              27



/* @} */

/**
 * @name Security constants
 * @ingroup g_zps_nwk_sap_sec
 * Security constant values not in PIB or compile-time configurable
 * @note ZPS_NWK_MAX_ACL_ENTRIES is configurable and will determine how much memory is required.
 * @{
 */
/** Maximum security material length */
#define ZPS_NWK_MAX_SECURITY_MATERIAL_LEN   26
#ifdef ENABLE_OPT_SECURITY
#ifdef EMBEDDED
/** Maximum number of ACL entries */
#define ZPS_NWK_MAX_ACL_ENTRIES             16
#else
/** Maximum number of ACL entries */
#define ZPS_NWK_MAX_ACL_ENTRIES             255
#endif
#else
#define ZPS_NWK_MAX_ACL_ENTRIES             1
#endif
/* @} */

/**
 * @name Vendor-specific constants
 * @ingroup g_zps_nwk_sap_vs
 * Vendor-specific constant values not defined by specification
 * @{
 */
/** Debug message maximum length */
#define ZPS_NWK_VS_DEBUG_LEN                128

/* @} */

/**
 * @name Derived constants
 * @ingroup g_zps_nwk_sap_vs
 * Constant values derived from stack profile
 * @{
 */

/** Network diameter */
#define ZPS_NWK_DIAMETER                   (2 * ZPS_NWK_OPT_FS_MAX_DEPTH)

/** Maximum devices:
 * x = nwkMaxRouters
 * y = nwkMaxDepth
 * z = nwkMaxChildren
 * SUM[n=0:n=y](x^n) + SUM[n=0:n=y-1](z - x)x^n) + */

/** Maximum number of neighbor table entries: in zps_nwk_nib.h */

/* @} */

/**
 * Neighbor table association response values.
 * These are actually defined in 802.15.4 but needn't be really
 * as they go transparently through the MAC
 */
#define ZPS_NWK_NT_SUCCESS                 0
#define ZPS_NWK_NT_PAN_AT_CAPACITY         1
#define ZPS_NWK_NT_PAN_ACCESS_DENIED       2

/**
 * @name Form constants
 * @ingroup g_zps_nwk_sap
 * Constant used for network formation
 * @{
 */
#define ZPS_NWK_NULL_PAN_ID 0x4000
#define ZPS_NWK_INVALID_NWK_ADDR 0xfffe
#define ZPS_NWK_NULL_EXT_PAN_ID ((uint64)0)
#define ZPS_NWK_NULL_EXT_ADDR ((uint64)0)
#define ZPS_NWK_NULL_LOGICAL_CHAN ((uint8)0)
/* @} */

/**
 * @name Broadcast addresses
 * @ingroup g_zps_nwk_sap
 * @{
 */
#define ZPS_NWK_BCAST_ADDR       0xffff
#define ZPS_NWK_BCAST_ADDR_RXWI  0xfffd
#define ZPS_NWK_BCAST_ADDR_ZCZR  0xfffc
#define ZPS_NWK_BCAST_ADDR_LPZR  0xfffb
#define ZPS_NWK_BCAST_LOW_ADDR   ZPS_NWK_BCAST_ADDR_ZCZR /* Low power routers not implemented yet */
/* @} */


/**
 * @name Beacon Payload bitmaps
 * @ingroup g_zps_nwk_sap
 * Beacon payload bitmaps
 * @{
 */
#define ZPS_NWK_BCN_PL_PROTOCOL_ID(x)       ((x)[0])
#define ZPS_NWK_BCN_PL_STACK_PROFILE(x)     ((x)[1] & 0xf)
#define ZPS_NWK_BCN_PL_PROTOCOL_VER(x)      ((x)[1] >> 4)
#define ZPS_NWK_BCN_PL_ZR_CAPACITY(x)       (((x)[2] >> 2) & 0x1)
#define ZPS_NWK_BCN_PL_DEVICE_DEPTH(x)      (((x)[2] >> 3) & 0xf)
#define ZPS_NWK_BCN_PL_ZED_CAPACITY(x)      (((x)[2] >> 7) & 0x1)
#ifdef WWAH_SUPPORT
#define ZPS_NWK_BCN_PL_PARENT_PRIORITY(x)      (((x)[2]) & 0x3)
#endif
#define ZPS_NWK_BCN_PL_EXT_PAN_ID_PTR(x)    &((x)[3])
#define ZPS_NWK_BCN_PL_TX_OFFSET_PTR(x)     &((x)[11])
#define ZPS_NWK_BCN_PL_NWK_UPDATE_ID(x)     ((x)[14])
/* @} */

/**************************/
/**** TYPE DEFINITIONS ****/
/**************************/

/****************************/
/**** General Structures ****/
/****************************/

/**
 * @ingroup g_zps_nwk_sap
 * @brief ZPS NWK SAP Type.
 *
 * Enumeration of SAP type
 */
typedef enum
{
    ZPS_NWK_SAP_NLME = 0,   /**< SAP Type is NLME */
    ZPS_NWK_SAP_NLDE = 1,   /**< SAP Type is NLDE */
    NUM_ZPS_NWK_SAP
} ZPS_teNwkSap;

/**
 * @ingroup g_zps_nwk_sap
 * @brief ZPS NWK Enumeration Type.
 *
 * Enumerations for NWK layer as defined in Table 3.56 (053474r15)
 * @note Refer to specification for definitive definitions.
 */
typedef enum
{
    ZPS_NWK_ENUM_SUCCESS = 0,                 /**< Success (0x00) */
    ZPS_NWK_ENUM_INVALID_PARAMETER = 0xC1,    /**< An invalid or out-of-range parameter has been passed (0xc1) */
    ZPS_NWK_ENUM_INVALID_REQUEST,             /**< Request cannot be processed (0xc2) */
    ZPS_NWK_ENUM_NOT_PERMITTED,               /**< NLME-JOIN.request not permitted (0xc3) */
    ZPS_NWK_ENUM_STARTUP_FAILURE,             /**< NLME-NETWORK-FORMATION.request failed (0xc4) */
    ZPS_NWK_ENUM_ALREADY_PRESENT,             /**< NLME-DIRECT-JOIN.request failure - device already present (0xc5) */
    ZPS_NWK_ENUM_SYNC_FAILURE,                /**< NLME-SYNC.request has failed (0xc6) */
    ZPS_NWK_ENUM_NEIGHBOR_TABLE_FULL,         /**< NLME-DIRECT-JOIN.request failure - no space in router table (0xc7) */
    ZPS_NWK_ENUM_UNKNOWN_DEVICE,              /**< NLME-LEAVE.request failure - device not in neighbor table (0xc8) */
    ZPS_NWK_ENUM_UNSUPPORTED_ATTRIBUTE,       /**< NLME-GET/SET.request unknown attribute identifier (0xc9) */
    ZPS_NWK_ENUM_NO_NETWORKS,                 /**< NLME-JOIN.request saw no networks (0xca) */
    ZPS_NWK_ENUM_RESERVED_1,                  /**< Reserved (0xcb) */
    ZPS_NWK_ENUM_MAX_FRM_CTR,                 /**< Security processing has failed on outgoing frame due to max. frm counter (0xcc) */
    ZPS_NWK_ENUM_NO_KEY,                      /**< Security processing has failed on outgoing frame due to no key (0xcd) */
    ZPS_NWK_ENUM_BAD_CCM_OUTPUT,              /**< Security processing has failed on outgoing frame due CCM* processing (0xce) */
    ZPS_NWK_ENUM_NO_ROUTING_CAPACITY,         /**< Attempt at route discovery has failed due to lack of table space (0xcf) */
    ZPS_NWK_ENUM_ROUTE_DISCOVERY_FAILED,      /**< Attempt at route discovery has failed due any reason except lack of table space (0xd0) */
    ZPS_NWK_ENUM_ROUTE_ERROR,                 /**< NLDE-DATA.request has failed due to routing failure on sending device (0xd1) */
    ZPS_NWK_ENUM_BT_TABLE_FULL,               /**< Broadcast or broadcast-mode multicast has failed as there is no room in BTT (0xd2) */
    ZPS_NWK_ENUM_FRAME_NOT_BUFFERED,          /**< Insufficient buffering available or Unicast mode multi-cast frame was discarded pending route discovery (0xd3) */
    ZPS_NWK_ENUM_FRAME_IS_BUFFERED            /**< Unicast mode frame on the pending frame (0xd4) */
} ZPS_teNwkEnum;

/**
 * @ingroup g_zps_nwk_sap
 * @brief ZPS NWK Status Enumeration Type.
 *
 * Enumerations for NWK status layer as defined in Table 3.43 (053474r16)
 * @note Refer to specification for definitive definitions.
 */
typedef enum
{
    ZPS_NWK_ST_NO_ROUTE_AVAILABLE = 0,        /**< No route available (0x00) */
    ZPS_NWK_ST_TREE_LINK_FAILURE,             /**< Tree link failure (0x01) */
    ZPS_NWK_ST_NON_TREE_LINK_FAILURE,         /**< Non-tree link failure (0x02) */
    ZPS_NWK_ST_LOW_BATTERY_LEVEL,             /**< Low battery level (0x03) */
    ZPS_NWK_ST_NO_ROUTING_CAPACITY,           /**< No routing capacity (0x04) */
    ZPS_NWK_ST_NO_INDIRECT_CAPACITY,          /**< No indirect capacity (0x05) */
    ZPS_NWK_ST_INDIRECT_TRANSACTION_EXPIRY,   /**< Indirect transaction expiry (0x06) */
    ZPS_NWK_ST_TARGET_DEVICE_UNAVAILABLE,     /**< Target device unavailable (0x07) */
    ZPS_NWK_ST_TARGET_ADDRESS_UNALLOCATED,    /**< Target address unallocated (0x08) */
    ZPS_NWK_ST_PARENT_LINK_FAILURE,           /**< Parent link failure (0x09) */
    ZPS_NWK_ST_VALIDATE_ROUTE,                /**< Validate route (0x0a) */
    ZPS_NWK_ST_SOURCE_ROUTE_FAILURE,          /**< Source route failure (0x0b) */
    ZPS_NWK_ST_MANY_TO_ONE_ROUTE_FAILURE,     /**< Many-to-one route failure (0x0c) */
    ZPS_NWK_ST_ADDRESS_CONFLICT,              /**< Address conflict (0x0d) */
    ZPS_NWK_ST_VERIFY_ADDRESSES,              /**< Verify addresses (0x0e) */
    ZPS_NWK_ST_PAN_ID_UPDATE,                 /**< PAN Identifier update (0x0f) */
    ZPS_NWK_ST_NETWORK_ADDRESS_UPDATE,        /**< Network address update (0x10) */
    ZPS_NWK_ST_BAD_FRAME_COUNTER,             /**< Bad frame counter (0x11) */
    ZPS_NWK_ST_BAD_KEY_SEQ_NUMBER,            /**< Bad key sequence number (0x12) */
} ZPS_teNwkStatus;

/**
 * @ingroup g_zps_nwk_sap_pib
 * @brief ZPS NWK NIB attribute enumerations.
 *
 * Enumerations of NIB attribute as defined in table 3.44 (053474r15)
 * @note Refer to specification for definitive definitions.
 */
typedef enum
{
    ZPS_NWK_NIB_ATTR_SEQUENCE_NUMBER                   = 0x81, /**< nwkSequenceNumber */
    ZPS_NWK_NIB_ATTR_PASSIVE_ACK_TIMEOUT               = 0x82, /**< nwkPassiveAckTimeout */
    ZPS_NWK_NIB_ATTR_MAX_BROADCAST_RETRIES             = 0x83, /**< nwkMaxBroadcastRetries */
    ZPS_NWK_NIB_ATTR_MAX_CHILDREN                      = 0x84, /**< nwkMaxChildren */
    ZPS_NWK_NIB_ATTR_MAX_DEPTH                         = 0x85, /**< nwkMaxDepth */
    ZPS_NWK_NIB_ATTR_MAX_ROUTERS                       = 0x86, /**< nwkMaxRouters */
    ZPS_NWK_NIB_ATTR_NEIGHBOR_TABLE                    = 0x87, /**< nwkNeighborTable */
    ZPS_NWK_NIB_ATTR_NETWORK_BROADCAST_DELIVERY_TIME   = 0x88, /**< nwkNetworkBroadcastDeliveryTime */
    ZPS_NWK_NIB_ATTR_REPORT_CONSTANT_COST              = 0x89, /**< nwkReportConstantCost */
    ZPS_NWK_NIB_ATTR_ROUTE_DISCOVERY_RETRIES_PERMITTED = 0x8A, /**< nwkRouteDiscoveryRetriesPermitted */
    ZPS_NWK_NIB_ATTR_ROUTE_TABLE                       = 0x8B, /**< nwkRouteTable */
    ZPS_NWK_NIB_ATTR_SYM_LINK                          = 0x8E, /**< nwkSymLink */
    ZPS_NWK_NIB_ATTR_CAPABILITY_INFORMATION            = 0x8F, /**< nwkCapabilityInformation */
    ZPS_NWK_NIB_ATTR_ADDR_ALLOC                        = 0x90, /**< nwkAddrAlloc */
    ZPS_NWK_NIB_ATTR_USE_TREE_ROUTING                  = 0x91, /**< nwkUseTreeRouting */
    ZPS_NWK_NIB_ATTR_MANAGER_ADDR                      = 0x92, /**< nwkManagerAddr */
    ZPS_NWK_NIB_ATTR_MAX_SOURCE_ROUTE                  = 0x93, /**< nwkMaxSourceRoute */
    ZPS_NWK_NIB_ATTR_TRANSACTION_PERSISTENCE_TIME      = 0x95, /**< nwkTransactionPersistenceTime */
    ZPS_NWK_NIB_ATTR_NETWORK_ADDRESS                   = 0x96, /**< nwkNwkAddress */
    ZPS_NWK_NIB_ATTR_STACK_PROFILE                     = 0x97, /**< nwkStackProfile */
    ZPS_NWK_NIB_ATTR_BROADCAST_TRANSACTION_TABLE       = 0x98, /**< nwkBroadcastTransactionTable */
    ZPS_NWK_NIB_ATTR_GROUP_ID_TABLE                    = 0x99, /**< nwkGroupIDTable */
    ZPS_NWK_NIB_ATTR_EXTENDED_PAN_ID                   = 0x9A, /**< nwkExtendedPANID */
    ZPS_NWK_NIB_ATTR_USE_MULTICAST                     = 0x9B, /**< nwkUseMulticast */
    ZPS_NWK_NIB_ATTR_ROUTE_RECORD_TABLE                = 0x9C, /**< nwkRouteRecordTable (separate table) */
    ZPS_NWK_NIB_ATTR_IS_CONCENTRATOR                   = 0x9D, /**< nwkIsConcentrator */
    ZPS_NWK_NIB_ATTR_CONCENTRATOR_RADIUS               = 0x9E, /**< nwkConcentratorRadius */
    ZPS_NWK_NIB_ATTR_CONCENTRATOR_DISCOVERY_TIME       = 0x9F, /**< nwkConcentratorDiscoveryTime */
    ZPS_NWK_NIB_ATTR_SECURITY_LEVEL                    = 0xA0, /**< nwkSecurityLevel */
    ZPS_NWK_NIB_ATTR_SECURITY_MATERIAL_SET             = 0xA1, /**< nwkSecurityMaterialSet (separate table) */
    ZPS_NWK_NIB_ATTR_ACTIVE_KEY_SEQ_NUMBER             = 0xA2, /**< nwkActiveKeySeqNumber */
    ZPS_NWK_NIB_ATTR_ALL_FRESH                         = 0xA3, /**< nwkAllFresh */
    ZPS_NWK_NIB_ATTR_SECURE_ALL_FRAMES                 = 0xA5, /**< nwkSecureAllFrames */
    ZPS_NWK_NIB_ATTR_LINK_STATUS_PERIOD                = 0xA6, /**< nwkLinkStatusPeriod */
    ZPS_NWK_NIB_ATTR_ROUTER_AGE_LIMIT                  = 0xA7, /**< nwkRouterAgeLimit */
    ZPS_NWK_NIB_ATTR_UNIQUE_ADDR                       = 0xA8, /**< nwkUniqueAddr */
    NUM_ZPS_NWK_ATTR_PIB                                /**< (endstop) */
} ZPS_teNwkNibAttr;

/**
 * @ingroup g_zps_nwk_sap
 * @brief ZPS NWK Rejoin enumeration.
 *
 * Enumeration of NWK Rejoin enumeration
 * @note The 'channel change' rejoin is not really a rejoin, just a method to change channel
 */
typedef enum
{
    ZPS_NWK_REJOIN_ASSOC_JOIN = 0,            /**< Join a network using the MAC association procedure */
    ZPS_NWK_REJOIN_ORPHAN_REJOIN,             /**< Join or rejoin a network using the orphaning procedure */
    ZPS_NWK_REJOIN_NWK_REJOIN,                /**< Join or rejoin a network using the NWK rejoin procedure */
    ZPS_NWK_REJOIN_CHG_CHAN,                  /**< Switch the operating channel for a device that is joined to a network */
    ZPS_NWK_REJOIN_NO_DISC,                   /**< Rejoin process without discovery and back to parent*/
    ZPS_NWK_REJOIN_NO_DISC_TRY_NEXT_PARENT,   /**< Rejoin process without discovery try next potential parent */
    NUM_ZPS_NWK_REJOIN
} ZPS_teNwkRejoin;

/**
 * @ingroup g_zps_nwk_sap
 * @brief ZPS NWK Discover route enumeration for route discovery suppression
 *
 * Enumeration of ZPS NWK Discover route for route discovery suppression
 * @note
 */
typedef enum
{
    ZPS_NWK_DISCOVER_ROUTE_SUPPRESS = 0,    /**< Suppress route discovery */
    ZPS_NWK_DISCOVER_ROUTE_ENABLE = 1,      /**< Enable route discovery */
} ZPS_teNwkDiscoverRoute;

/**
 * @ingroup g_zps_nwk_sap
 * @brief ZPS NWK Discover route enumeration for address mode
 *
 * Enumeration of ZPS NWK Discover route for address mode
 * @note
 */
typedef enum
{
    ZPS_NWK_ROUTE_DISC_ADDR_MODE_MTO1 = 0,      /**< Many-to-one */
    ZPS_NWK_ROUTE_DISC_ADDR_MODE_MULTICAST = 1, /**< Multicast */
    ZPS_NWK_ROUTE_DISC_ADDR_MODE_UNICAST = 2,   /**< Unicast */
} ZPS_teNwkRouteDiscAddrMode;

/**
 * @ingroup g_zps_nwk_sap_pib
 * @brief ZPS NWK NIB union
 *
 * Union of all NIB attribute values as defined in table 3.44 (053474r15)
 */
typedef union
{
    uint8  u8SequenceNumber;                    /**< nwkSequenceNumber */
    uint8  u8PassiveAckTimeout;                 /**< nwkPassiveAckTimeout */
    uint8  u8MaxBroadcastRetries;               /**< nwkMaxBroadcastRetries */
    uint8  u8MaxChildren;                       /**< nwkMaxChildren */
    uint8  u8MaxDepth;                          /**< nwkMaxDepth */
    uint8  u8MaxRouters;                        /**< nwkMaxRouters */
    /* Neighbour table separate */              /**< nwkNeighborTable */
    uint8  u8NetworkBroadcastDeliveryTime;      /**< nwkNetworkBroadcastDeliveryTime */
    uint8  u8ReportConstantCost;                /**< nwkReportConstantCost */
    uint8  u8RouteDiscoveryRetriesPermitted;    /**< nwkRouteDiscoveryRetriesPermitted */
    /* Route table separate */                  /**< nwkRouteTable */
    uint8  u8SymLink;                           /**< nwkSymLink: bool */
    uint8  u8CapabilityInformation;             /**< nwkCapabilityInformation */
    uint8  u8AddrAlloc;                         /**< nwkAddrAlloc */
    uint8  u8UseTreeRouting;                  /**< nwkUseTreeAddrAlloc: bool */
    uint16 u16ManagerAddr;                      /**< nwkManagerAddr */
    uint8  u8MaxSourceRoute;                    /**< nwkMaxSourceRoute */
    uint8  u8UpdateId;                          /**< nwkUpdateID */
    /* Transaction persistence time in MAC */   /**< nwkTransactionPersistenceTime */
    /* Network Address in MAC */                /**< nwkNwkAddress */
    /* Stack profile constant? */               /**< nwkStackProfile */
    /* Broadcast transaction table separate */  /**< nwkBroadcastTransactionTable */
    /* Group ID table separate */               /**< nwkGroupIDTable */
    uint64 u64ExtendedPanId;                    /**< nwkExtendedPANID */
    uint8  u8UseMulticast;                      /**< nwkUseMulticast: bool */
    /* Route record table separate */           /**< nwkRouteRecordTable */
    uint8  u8IsConcentrator;                    /**< nwkIsConcentrator: bool */
    uint8  u8ConcentratorRadius;                /**< nwkConcentratorRadius */
    uint8  u8ConcentratorDiscoveryTime;         /**< nwkConcentratorDiscoveryTime */
    uint8  u8SecurityLevel;                     /**< nwkSecurityLevel */
    /* Security material set separate */        /**< nwkSecurityMaterialSet */
    uint8  u8ActiveKeySeqNumber;                /**< nwkActiveKeySeqNumber */
    uint8  u8AllFresh;                          /**< nwkAllFresh */
    uint8  u8SecureAllFrames;                   /**< nwkSecureAllFrames */
    uint8  u8LinkStatusPeriod;                  /**< nwkLinkStatusPeriod */
    uint8  u8RouterAgeLimit;                    /**< nwkRouterAgeLimit */
    uint8  u8UniqueAddr;                        /**< nwkUniqueAddr */
    /* Address map separate */                  /**< nwkAddressMap */
    /* Time stamp usage constant? (FALSE) */    /**< nwkTimeStamp */
    /* PAN ID in MAC */                         /**< nwkPANId */
    uint16 u16TxTotal;                          /**< nwkTxTotal */
} ZPS_tuNwkNib;

/**
 * @ingroup g_zps_nwk_sap_disc
 * @brief Network Descriptor
 *
 * Network Descriptor as defined in table 3.8 (053474r17).
 * Indicates Network parameters to a device obtained from a ZPS NWK Beacon.
 * @note Beacon order and superframe order removed as superfluous. If they
 * are needed in a ZDP implementation, will be reinstated then.
 */
typedef struct
{
    uint64 u64ExtPanId;         /**< Extended PAN ID */
    uint8  u8LogicalChan;       /**< Logical channel */
    uint8  u8StackProfile;      /**< Stack profile */
    uint8  u8ZigBeeVersion;     /**< ZigBee version */
    uint8  u8PermitJoining;     /**< Permit Joining */
    uint8  u8RouterCapacity;    /**< Router capacity */
    uint8  u8EndDeviceCapacity; /**< End device capacity */
#ifdef WWAH_SUPPORT
    uint8  u8ParentCapacity;    /**< Parent Capcity*/
#endif
} ZPS_tsNwkNetworkDescr;

/**
 * @ingroup g_zps_nwk_sap
 * @brief Scan parameters
 *
 * Scan parameters grouped together
 * @note It makes sense to do this to commonise scan submission code
 */
typedef struct
{
    uint32 u32ScanChannels;   /**< Channels to scan */
    uint8  u8ScanDuration;    /**< Scan duration */
} ZPS_tsNwkScanParams;

/**
 * @ingroup g_zps_nwk_sap
 * @brief Channel List Structure
 *
 */
#define MAX_CHANNEL_PAGES 4
typedef struct
{
	uint32	u32ChannelField[MAX_CHANNEL_PAGES];				/* Array of channel fields */
	uint8	u8ChannelPageCount;								/* Number of channel fields to follow */
}ZPS_tsNwkChannelMaskList;
/**********************/
/**** NLME Request ****/
/**********************/

/**
 * @defgroup g_zps_nwk_sap_nlme_req NLME Request objects
 * @ingroup g_zps_nwk_sap_nlme
 *
 * These are passed in a call to ZPS_NWK_vHandleNlmeReqRsp.
 * Confirms to a Request will either be passed back synchronously on the function return,
 * or a special 'deferred' confirm will come back asynchronously via the
 * Deferred Confirm/Indication callback.
 * Responses have no effective confirmation of sending as they are in response to
 * an Indication; this will be indicated in the synchronous Confirm passed back.
 */

/**
 * @defgroup g_zps_nwk_sap_nlme_req_spec NLME Request ZPS NWK specification parameters
 * @ingroup g_zps_nwk_sap_nlme_req
 *
 * @{
 */

/**
 * @brief Structure for NLME-NETWORK-DISCOVERY.request
 *
 * Network discovery request. Use type ZPS_NWK_NLME_REQ_NETWORK_DISCOVERY
 */
typedef struct
{
    ZPS_tsNwkScanParams sScan;    /**< Scan parameters */
    bool_t              bReturnActive;
} ZPS_tsNwkNlmeReqNetworkDiscovery;

/**
 * @brief Structure for NLME-NETWORK-FORMATION.request
 *
 * Network formation request. Use type ZPS_NWK_NLME_REQ_NETWORK_FORMATION
 */
typedef struct
{
    ZPS_tsNwkScanParams  sScan;       /**< Scan parameters */
} ZPS_tsNwkNlmeReqNetworkFormation;

/**
 * @brief Structure for NLME-PERMIT-JOINING.request
 *
 * Permit joining request. Use type ZPS_NWK_NLME_REQ_PERMIT_JOINING
 */
typedef struct
{
    uint8 u8PermitDuration; /**< How long in seconds the JC/JR will allow associations for */
} ZPS_tsNwkNlmeReqPermitJoining;

/**
 * @brief Structure for NLME-ED-SCAN.request
 *
 * Perform an energy detect scan. Use type ZPS_NWK_NLME_REQ_ED_SCAN
 */
typedef struct
{
    ZPS_tsNwkScanParams sScan;           /**< Scan parameters */
} ZPS_tsNwkNlmeReqEdScan;

/**
 * @brief Structure for NLME-JOIN.request
 *
 * Join a network request. Use type ZPS_NWK_NLME_REQ_JOIN
 */
typedef struct
{
    ZPS_tsNwkScanParams sScan;            /**< Scan parameters */
    uint64              u64ExtPanId;      /**< Extended PAN ID */
    uint8               u8RejoinNetwork;  /**< Whether rejoining using the orphaning procedure */
    uint8               u8Capability;     /**< Capability flags - bizarrely determined by the MAC */
    uint8               u8SecurityEnable; /**< Security enabled / disabled */
} ZPS_tsNwkNlmeReqJoin;

/**
 * @brief Structure for NLME-DIRECT-JOIN.request
 *
 * Join a device to the network directly request. Use type ZPS_NWK_NLME_REQ_DIRECT_JOIN
 */
typedef struct
{
    uint64 u64DeviceAddress; /**< Device's IEEE address */
    uint16 u16NwkAddress;
    uint8  u8Capability;     /**< Capability information of device */
} ZPS_tsNwkNlmeReqDirectJoin;

/**
 * @brief Structure for NLME-LEAVE.request
 *
 * Leave network request. Use type ZPS_NWK_NLME_REQ_LEAVE
 */
typedef struct
{
    uint64 u64DeviceAddress; /**< Device's IEEE address */
    uint8  u8RemoveChildren; /**< Capability information of device */
    uint8  u8Rejoin;         /**< Rejoin network */
} ZPS_tsNwkNlmeReqLeave;

/**
 * @brief Structure for NLME-RESET.request
 *
 * Reset request. Use type ZPS_NWK_NLME_REQ_RESET
 */
typedef struct
{
    uint8 u8WarmStart;  /**< Whether or not a warm start is done, i.e. NIB/PIB values changed or not */
} ZPS_tsNwkNlmeReqReset;

/**
 * @brief Structure for NLME-GET.request
 *
 * NIB get request. Use type ZPS_NWK_NLME_REQ_GET
 */
typedef struct
{
    uint8 u8NibAttribute;   /**< Attribute @sa ZPS_teNwkNibAttr */
} ZPS_tsNwkNlmeReqGet;

/**
 * @brief Structure for NLME-SET.request
 *
 * NIB set request. Use type ZPS_NWK_NLME_REQ_SET
 */
typedef struct
{
    uint8        u8NibAttribute;          /**< Attribute @sa ZPS_teNwkNibAttr */
    uint8        u8NibAttributeLength;    /**< Length of attribute */
    ZPS_tuNwkNib uNibAttributeValue;      /**< Attribute value */
} ZPS_tsNwkNlmeReqSet;

/**
 * @brief Structure for NLME-ROUTE-DISCOVERY.request
 *
 * Route discovery request. Use type ZPS_NWK_NLME_REQ_ROUTE_DISCOVERY
 */
typedef struct
{
    uint8  u8Radius;       /**< Number of hops route request will travel through nwk */
    uint8  u8DstAddrMode;  /**< Destination address mode */
    uint16 u16NwkDstAddr;  /**< Destination Network address */
    uint8  u8NoRouteCache; /**< Whether or not there is expected to be enough mem for each route record */
} ZPS_tsNwkNlmeReqRouteDiscovery;


/**
 * @brief Structure for NLME-SET-INTERFACE.request
 *
 * Route discovery request. Use type ZPS_NWK_NLME_REQ_SET_INTERFACE
 */
typedef struct
{
    ZPS_tsNwkChannelMaskList sSupportedChannels;	/**< Channel Mask List Structure */
    uint32 u32ChannelToUse;  	   					/**< Channel To Use */
    uint8  u8InterfaceIndex;       					/**< MAC Interface ID */
    bool_t bState;  			   					/**< Enable or Disable */
    bool_t bRoutersAllowed;							/**< Routers Allowed or Not */
} ZPS_tsNwkNlmeReqSetInterface;


/**
 * @brief Structure for NLME-GET-INTERFACE.request
 *
 * Route discovery request. Use type ZPS_NWK_NLME_REQ_GET_INTERFACE
 */
typedef struct
{
    uint8  u8InterfaceIndex;       				/**< MAC Interface ID */
} ZPS_tsNwkNlmeReqGetInterface;
/* @} */

/**
 * @defgroup g_zps_nwk_sap_nlme_req_vs NLME Request Vendor specific parameters
 * @ingroup g_zps_nwk_sap_nlme_req g_zps_nwk_sap_vs
 *
 * @{
 */

/* @} */

/**********************/
/**** NLME Confirm ****/
/**********************/

/**
 * @defgroup g_zps_nwk_sap_nlme_cfm ZPS NWK NLME Confirm objects
 * @ingroup g_zps_nwk_sap_nlme
 *
 * These come back synchronously as a returned parameter in the Request/Response call.
 * They can also be deferred and asynchronously posted via the Deferred Confirm/Indication callback.
 */

/**
 * @defgroup g_zps_nwk_sap_nlme_cfm_spec NLME Confirm ZPS NWK specification parameters
 * @ingroup g_zps_nwk_sap_nlme_cfm
 *
 * @{
 */

/**
 * @brief Common structure for all confirms
 */
typedef struct
{
    uint8 u8Status; /**< Status is common to all confirms and is always the first entry */
} ZPS_tsNwkNlmeCfmCommon;

/**
 * @brief Structure for NLME-NETWORK-DISCOVERY.confirm
 *
 * Network discovery - confirmation
 * @note There is an additional unscanned channels parameter. This is not in
 * the spec. but is very useful to know for further submissions.
 */
typedef struct
{
    uint8                 u8Status;                                    /**< Status of network discovery @sa ZPS_teNwkEnum */
    uint8                 u8NwkCount;                                  /**< Number of networks discovered */
    uint32                u32UnscannedChannels;                        /**< Unscanned Channels - NOT IN SPEC */
    ZPS_tsNwkNetworkDescr * psNwkDesc;
} ZPS_tsNwkNlmeCfmNetworkDiscovery;

typedef struct
{
    uint8                 u8Status;                                    /**< Status of network discovery @sa ZPS_teNwkEnum */
    uint8                 u8NwkCount;                                  /**< Number of networks discovered */
    uint32                u32UnscannedChannels;                        /**< Unscanned Channels - NOT IN SPEC */
    ZPS_tsNwkNetworkDescr asNwkDescr[ZPS_NWK_MAX_DISC_NWK_DESCRS]; /**< List of Network Descriptors */
} ZPS_tsNwkNlmeCfmNetworkDiscoveryCtx;

/**
 * @brief Structure for NLME-NETWORK-FORMATION.confirm
 *
 * Network formation - confirmation
 */
typedef struct
{
    uint8 u8Status; /**< Status of network formation @sa ZPS_teNwkEnum */
} ZPS_tsNwkNlmeCfmNetworkFormation;

/**
 * @brief Structure for NLME-PERMIT-JOINING.confirm
 *
 * Permit joining - confirmation
 */
typedef struct
{
    uint8 u8Status; /**< Status of permit joining @sa ZPS_teNwkEnum */
} ZPS_tsNwkNlmeCfmPermitJoining;

/**
 * @brief Structure for NLME-START-ROUTER.confirm
 *
 * Start as router - confirmation
 */
typedef struct
{
    uint8 u8Status; /**< Status of permit joining @sa ZPS_teNwkEnum */
} ZPS_tsNwkNlmeCfmStartRouter;

/**
 * @brief Structure for NLME-JOIN.confirm
 *
 * Join a network - confirmation
 */
typedef struct
{
    uint8  u8Status;        /**< Status of join @sa ZPS_teNwkEnum */
    uint8  u8ActiveChannel; /**< Active channel */
    uint16 u16NwkAddr;      /**< Short address of joining device (added in r08) */
    uint64 u64ExtPanId;     /**< Extended PAN ID */
} ZPS_tsNwkNlmeCfmJoin;

/**
 * @brief Structure for NLME-DIRECT-JOIN.confirm
 *
 * Join a device to the network directly - confirmation.
 */
typedef struct
{
    uint8  u8Status;         /**< Status of direct join @sa ZPS_teNwkEnum */
    uint64 u64DeviceAddress; /**< Device's IEEE address */
} ZPS_tsNwkNlmeCfmDirectJoin;

/**
 * @brief Structure for NLME-LEAVE.confirm
 *
 * Leave network - confirmation
 */
typedef struct
{
    uint8  u8Status;         /**< Status of direct join @sa ZPS_teNwkEnum */
    bool_t bRejoin;
    uint64 u64DeviceAddress; /**< Device's IEEE address */
} ZPS_tsNwkNlmeCfmLeave;

/**
 * @brief Structure for NLME-RESET.confirm
 *
 * Reset - confirmation
 */
typedef struct
{
    uint8 u8Status; /**< Status of reset @sa ZPS_teNwkEnum */
} ZPS_tsNwkNlmeCfmReset;

/**
 * @brief Structure for NLME-SYNC.confirm
 *
 * Synchronisation - confirmation
 */
typedef struct
{
    uint8 u8Status; /**< Status of synchronisation @sa ZPS_teNwkEnum */
} ZPS_tsNwkNlmeCfmSync;

/**
 * @brief Structure for NLME-GET.confirm
 *
 * NIB get - confirmation
 */
typedef struct
{
    uint8        u8Status;             /**< Status of get @sa ZPS_teNwkEnum */
    uint8        u8NibAttribute;       /**< Attribute @sa ZPS_teNwkNibAttr */
    uint8        u8NibAttributeLength; /**< Length of attribute */
    ZPS_tuNwkNib uNibAttributeValue;   /**< Attribute value */
} ZPS_tsNwkNlmeCfmGet;

/**
 * @brief Structure for NLME-SET.confirm
 *
 * NIB set - confirmation
 */
typedef struct
{
    uint8 u8Status;       /**< Status of set @sa ZPS_teNwkEnum */
    uint8 u8NibAttribute; /**< Attribute @sa ZPS_teNwkNibAttr */
} ZPS_tsNwkNlmeCfmSet;

/**
 * @brief Structure for NLME-SET-INTERFACE.confirm
 *
 * NIB set - confirmation
 */
typedef struct
{
    uint8 u8Status;       /**< Status of set @sa ZPS_teNwkEnum */
} ZPS_tsNwkNlmeCfmSetInterface;

/**
 * @brief Structure for NLME-GET-INTERFACE.confirm
 *
 * NIB set - confirmation
 */
typedef struct
{
    ZPS_tsNwkChannelMaskList sSupportedChannels;	/**< Channel Mask List Structure */
    uint32 u32ChannelInUse;  	   					/**< Channel In Use */
    uint32 u32MacTxUcastAccRetry;				    /**< Current value of u32MacTxUcastAccRetry */
    uint32 u32MacTxUcastAvgRetry;                   /**< Current value of u32MacTxUcastAvgRetry */
    uint32 u32MacTxUcastFail;						/**< Current value of u32MacTxUcastFail */
    uint32 u32MacRxUcast;                           /**< Current value of u32MacRxUcast */
    uint32 u32MacTxUcast;                           /**< Current value of u32MacTxUcast */
    uint32 u32MacRxBcast;                           /**< Current value of u32MacRxBcast */
    uint32 u32MacTxBcast;                           /**< Current value of u32MacTxBcast */
    uint32 u32APSTxUcastRetry;						/**< Current value of u32APSTxUcastRetry */
    uint32 u32APSTxUcastFail;						/**< Current value of u32APSTxUcastFail */
    uint32 u32MacCCaFail;						    /**< Current value of u32MacCCaFail */
    uint8  u8Status;       							/**< Status of set @sa ZPS_teNwkEnum */
    uint8  u8InterfaceIndex;       					/**< MAC Interface ID */
    bool_t bState;  			   					/**< Enable or Disable */
    bool_t bRoutersAllowed;							/**< Routers Allowed or Not */
    bool_t bPowerNegotiationSupported;				/**< Power Negotiation Supported or Not */
} ZPS_tsNwkNlmeCfmGetInterface;

/**
 * @brief Structure for NLME-GET-RESOURCES.confirm
 *
 * NIB set - confirmation
 */
typedef struct
{
    uint8  u8NwkState;                              /**< Nwk state */
    uint8  u8MACTxFree;                             /**< Free MAC frames */
    uint8  u8MACTxTotal;                            /**< Total MAC frames */
    uint8  u8MACRxFree;                             /**< Free MAC frames */
    uint8  u8MACRxTotal;                            /**< Total MAC frames */
    uint8  u8NPdusFree;                             /**< Free NPDUs */
    uint8  u8NPdusPeak;                             /**< Peak allocated NPDUs */
    uint8  u8NPdusTotal;                            /**< Total NPDUs */
    uint16 u16APdusFree;                            /**< Free APDUs */
    uint16 u16APdusTotal;                           /**< Total APDUs */
    uint8  u8MCPSHandlesFree;                       /**< Free MCPS handles */
    uint8  u8MCPSHandlesTotal;                      /**< Total MCPS handles */
    uint16 u16ActCnt;                               /**< Activity counter */
} ZPS_tsNwkNlmeCfmGetResources;

/**
 * @brief Structure for NLME-ROUTE-DISCOVERY.confirm
 *
 * Route discovery - confirmation
 */
typedef struct
{
    uint16 u16DstAddress;      /**< destination address for which the route may be available */
    uint8 u8Status;            /**< Status of route discovery @sa ZPS_teNwkEnum */
    uint8 u8NetworkStatusCode; /**< Further information about a status of ROUTE_ERROR */
} ZPS_tsNwkNlmeCfmRouteDiscovery;

/**
 * @brief Structure for NLME-ED-SCAN.confirm
 *
 * Energy detect - confirmation
 */
typedef struct
{
    uint8 u8Status;                                /**< Status of scan request */
    uint8 u8ResultListSize;                        /**< Size of ED results list */
    uint8 au8EnergyDetect[ZPS_NWK_MAX_ED_RESULTS]; /**< ED results list */
} ZPS_tsNwkNlmeCfmEdScan;

/* @} */

/*************************/
/**** NLME Indication ****/
/*************************/

/**
 * @defgroup g_zps_nwk_sap_nlme_ind ZPS NWK NLME Indication objects
 * @ingroup g_zps_nwk_sap_nlme
 *
 * These are sent asynchronously via the registered Deferred Confirm/Indication callback
 */

/**
 * @defgroup g_zps_nwk_sap_nlme_ind_spec NLME Indication ZPS NWK specification parameters
 * @ingroup g_zps_nwk_sap_nlme_ind
 *
 * @{
 */

/**
 * @brief Structure for NLME-JOIN.indication
 *
 * Join indication. Uses type ZPS_NWK_NLME_IND_JOIN
 */
typedef struct
{
    uint64 u64ExtAddr;     /**< Device's IEEE address */
    uint16 u16NwkAddr;     /**< Extended address of device wishing to associate */
    uint8  u8Capability;   /**< Device capabilities */
    uint8  u8Rejoin;       /**< The nature of the join or rejoin */
    uint8  u8SecureRejoin; /**< Indicates if the rejoin was a secure rejoin */
} ZPS_tsNwkNlmeIndJoin;

/**
 * @brief Structure for NLME-LEAVE.indication
 *
 * Leave indication. Uses type ZPS_NWK_NLME_IND_LEAVE
 */
typedef struct
{
    uint64 u64DeviceAddr; /**< Device's IEEE address */
    uint8  u8Rejoin;      /**< Whether the device wishes to rejoin or not */
    bool_t bChild;        /**< Whether the leaving device is a child or not */
} ZPS_tsNwkNlmeIndLeave;

/**
 * @brief Structure for NLME-NWK-STATUS.indication
 *
 * Network Status indication. Uses type ZPS_NWK_NLME_IND_NWK_STATUS
 */
typedef struct
{
    uint8  u8Status;      /**< Status */
    uint16 u16NwkAddr;    /**< Network address */
} ZPS_tsNwkNlmeIndNwkStatus;


typedef struct
{
    uint16    u16DstAddress;
    uint8     u8Status;
} ZPS_tsNwkNlmeCfmRouteRecord;

typedef struct
{
    uint64    u64Address;
    uint32    u32Count;
    bool_t    bIncoming;
}ZPS_tsNwkNlmeCfmFCOverflow;

typedef enum
{
	ZPS_NWK_DUTYCYCLE_NORMAL=0,
	ZPS_NWK_DUTYCYCLE_LIMITED,
	ZPS_NWK_DUTYCYCLE_CRITICAL,
	ZPS_NWK_DUTYCYCLE_SUSPENDED,

} ZPS_teNwkNlmeIndDutyCycleMode;

/**
 * @brief Structure for NLME-NWK-DUTYCYCLE.indication
 *
 * Duty Cycle indication. Uses type ZPS_NWK_NLME_IND_NWK_DUTYCYCLE
 */
typedef struct
{
    uint8  u8Mode;      /**< Duty Cycle Status ZPS_teNwkNlmeIndDutyCycleMode */

} ZPS_tsNwkNlmeIndDutyCycle;


/* @} */

/***********************/
/**** NLME Response ****/
/***********************/

/**
 * @defgroup g_zps_nwk_sap_nlme_rsp NLME Response objects
 * @ingroup g_zps_nwk_sap_nlme
 *
 * There are no NLME Responses
 */

/*****************************************/
/**** NLME Request/Response Interface ****/
/*****************************************/

/**
 * @defgroup g_zps_nwk_sap_nlme_req_rsp_if NLME Request/Response interface
 * @ingroup g_zps_nwk_sap_nlme grp_zps_nwk_vs
 *
 * The interface for the client to issue an NLME Request or Response
 * is via a function call to ZPS_vNwkHandleNlmeReqRsp.
 * @li Request/Response parameters are passed in via psNlmeReqRsp
 * @li Synchronous Confirm parameters are passed out via psNlmeSyncCfm
 * @li Deferred Confirms are posted back asynchronously via the
 *     Deferred Confirm/Indication callback.
 * @note The ZPS NWK layer has no Responses but the mechanism will be left in for
 * future-proofing
   @note Responses have no effective confirmation of sending as they are in response to
 * an Indication; this will be indicated in the synchronous Confirm passed back.
 *
 * @{
 */

/**
 * @brief ZPS NWK NLME Request/Response enumeration.
 *
 * Enumeration of ZPS NWK NLME Request/Response
 * @note Must not exceed 256 entries
 * @note The order is deliberately different from the order in the spec. to be able to limit
 * entries in lookup tables
 */
typedef enum
{
    ZPS_NWK_NLME_REQ_NETWORK_DISCOVERY = 0,   /**< Use with ZPS_tsNwkNlmeReqNetworkDiscovery */
    ZPS_NWK_NLME_REQ_JOIN,                    /**< Use with ZPS_tsNwkNlmeReqJoin */
    ZPS_NWK_NLME_REQ_START_ROUTER,            /**< No parameters */
    ZPS_NWK_NLME_REQ_DIRECT_JOIN,             /**< Use with ZPS_tsNwkNlmeReqDirectJoin */
    ZPS_NWK_NLME_REQ_PERMIT_JOINING,          /**< Use with ZPS_tsNwkNlmeReqPermitJoining */
    ZPS_NWK_NLME_REQ_NETWORK_FORMATION,       /**< Use with ZPS_tsNwkNlmeReqNetworkFormation */
    ZPS_NWK_NLME_REQ_LEAVE,                   /**< Use with ZPS_tsNwkNlmeReqLeave */
    ZPS_NWK_NLME_REQ_SYNC,                    /**< No parameters (for non-beacon networks) */
    ZPS_NWK_NLME_REQ_ROUTE_DISCOVERY,         /**< Use with ZPS_tsNwkNlmeReqRouteDiscovery */
    ZPS_NWK_NLME_REQ_ED_SCAN,                 /**< Use with ZPS_tsNwkNlmeReqEdScan */
    ZPS_NWK_NLME_REQ_RESET,                   /**< Use with ZPS_tsNwkNlmeReqReset */
    ZPS_NWK_NLME_REQ_GET,                     /**< Use with ZPS_tsNwkNlmeReqGet */
    ZPS_NWK_NLME_REQ_SET,                     /**< Use with ZPS_tsNwkNlmeReqSet */
    ZPS_NWK_NLME_REQ_SET_INTERFACE,           /**< Use with ZPS_tsNwkNlmeReqSetInterface */
    ZPS_NWK_NLME_REQ_GET_INTERFACE,           /**< Use with ZPS_tsNwkNlmeReqGetInterface */
    ZPS_NWK_NLME_REQ_GET_RESOURCES,           /**< No parameters */
    NUM_ZPS_NWK_NLME_REQ                      /**< (endstop) */
} ZPS_teNwkNlmeReqRspType;

/**
 * @brief NLME Request/Response Parameter union
 *
 * Union of all the possible NLME Requests and Responses, including
 * all the vendor-specific requests
 */
typedef union
{
    /* NLME Requests */
    ZPS_tsNwkNlmeReqNetworkDiscovery sReqNetworkDiscovery;   /**< Network discovery request */
    ZPS_tsNwkNlmeReqNetworkFormation sReqNetworkFormation;   /**< Network formation request */
    ZPS_tsNwkNlmeReqPermitJoining    sReqPermitJoining;      /**< Permit joining request */
    ZPS_tsNwkNlmeReqEdScan           sReqEdScan;             /**< Energy detect scan request */
    ZPS_tsNwkNlmeReqJoin             sReqJoin;               /**< Join request */
    ZPS_tsNwkNlmeReqDirectJoin       sReqDirectJoin;         /**< Direct join request */
    ZPS_tsNwkNlmeReqLeave            sReqLeave;              /**< Leave request */
    ZPS_tsNwkNlmeReqReset            sReqReset;              /**< Reset request */
    ZPS_tsNwkNlmeReqGet              sReqGet;                /**< NIB get request */
    ZPS_tsNwkNlmeReqSet              sReqSet;                /**< NIB set request */
    ZPS_tsNwkNlmeReqRouteDiscovery   sReqRouteDiscovery;     /**< Route discovery request */
    ZPS_tsNwkNlmeReqSetInterface     sReqSetInterface;       /**< Set Interface request */
    ZPS_tsNwkNlmeReqGetInterface     sReqGetInterface;       /**< Get Interface request */
} ZPS_tuNlmeReqRspParam;

/**
 * @brief NLME Request/Response
 *
 * The object passed to ZPS_vNwkHandleNlmeReqRsp containing the request
 */
typedef struct
{
    uint8                 u8Type;        /**< Request type (@sa ZPS_teNwkNlmeReqRspType) */
    uint8                 u8ParamLength; /**< Parameter length in following union */
    uint16                u16Pad;        /**< To show padding octets */
    ZPS_tuNlmeReqRspParam uParam;        /**< Union of all possible Requests */
} ZPS_tsNwkNlmeReqRsp;

/**
 * @brief Synchronous confirm status
 *
 * Indicates in the synchronous confirm whether:
 * @li The Request was processed with or without error
 * @li The confirm will be deferred and posted via the Deferred Confirm/Indication callback
 * @li It is a dummy confirm to a Response.
 * @note NB Must not exceed 256 entries
 */
typedef enum
{
    ZPS_NWK_NLME_CFM_OK,             /**< Synchronous confirm without error */
    ZPS_NWK_NLME_CFM_ERROR,          /**< Synchronous confirm with error; see u8Status field */
    ZPS_NWK_NLME_CFM_DEFERRED,       /**< Asynchronous deferred confirm will occur */
    ZPS_NWK_NLME_CFM_NOT_APPLICABLE, /**< Dummy synchronous confirm for NLME responses */
    NUM_ZPS_NWK_NLME_CFM             /**< (endstop) */
} ZPS_teNwkNlmeSyncCfmStatus;

/**
 * @brief NLME Synchronous Confirm Parameter union
 *
 * Union of all the possible NLME Synchronous Confirms, including
 * all the vendor-specific confirms
 */
typedef union
{
    ZPS_tsNwkNlmeCfmCommon           sCommon;              /**< Structure common to all confirms */
    ZPS_tsNwkNlmeCfmNetworkDiscovery sCfmNetworkDiscovery; /**< Network Discovery confirm */
    ZPS_tsNwkNlmeCfmJoin             sCfmJoin;             /**< Join confirm */
    ZPS_tsNwkNlmeCfmStartRouter      sCfmStartRouter;      /**< Start Router confirm */
    ZPS_tsNwkNlmeCfmDirectJoin       sCfmDirectJoin;       /**< Direct Join confirm */
    ZPS_tsNwkNlmeCfmPermitJoining    sCfmPermitJoining;    /**< Permit Joining confirm */
    ZPS_tsNwkNlmeCfmNetworkFormation sCfmNetworkFormation; /**< Network Formation confirm */
    ZPS_tsNwkNlmeCfmLeave            sCfmLeave;            /**< Leave confirm */
    ZPS_tsNwkNlmeCfmSync             sCfmSync;             /**< Sync confirm */
    ZPS_tsNwkNlmeCfmRouteDiscovery   sCfmRouteDiscovery;   /**< Route discovery confirm */
    ZPS_tsNwkNlmeCfmEdScan           sCfmEdScan;           /**< ED Scan confirm */
    ZPS_tsNwkNlmeCfmReset            sCfmReset;            /**< Reset confirm */
    ZPS_tsNwkNlmeCfmGet              sCfmGet;              /**< Get confirm */
    ZPS_tsNwkNlmeCfmSet              sCfmSet;              /**< Set confirm */
    ZPS_tsNwkNlmeCfmSetInterface     sCfmSetInterface;     /**< Set Interface confirm */
    ZPS_tsNwkNlmeCfmGetInterface     sCfmGetInterface;     /**< Get Interface confirm */
    ZPS_tsNwkNlmeCfmGetResources     sCfmGetResources;     /**< Get Resources confirm */
} ZPS_tuNlmeSyncCfmParam;

/**
 * @brief NLME Synchronous Confirm
 *
 * The object returned by ZPS_NWK_vHandleNlmeReqRsp containing the synchronous confirm
 * @note All Confirms may also be sent asynchronously via the registered Deferred Confirm/Indication callback.
 * This is notified by returning ZPS_NWK_NLME_CFM_DEFERRED.
 * The confirm type is implied as corresponding to the request
 */
typedef struct
{
    uint8                  u8Status;      /**< Confirm status (@sa ZPS_teNwkNlmeSyncCfmStatus) */
    uint8                  u8ParamLength; /**< Parameter length in following union */
    uint16                 u16Pad;        /**< To show padding octets */
    ZPS_tuNlmeSyncCfmParam uParam;        /**< Union of all possible Confirms */
} ZPS_tsNwkNlmeSyncCfm;

/* @} */

/****************************************************/
/**** NLME Deferred Confirm/Indication Interface ****/
/****************************************************/

/**
 * @defgroup g_zps_nwk_sap_nlme_dcfm_ind_if NLME Deferred Confirm/Indication Interface
 * @ingroup g_zps_nwk_sap_nlme grp_zps_nwk_vs
 *
 * The interface for the client to receive an NLME Deferred Confirm or Indication
 * is via a function callback to the function registered using ZPS_vNwkRegisterNlmeDcfmIndCallbacks.
 *
 * @{
 */

/**
 * @brief Deferred Confirm/Indication type
 *
 * Indicates the type of deferred confirm or indication
 * @note NB Must not exceed 256 entries
 */
typedef enum
{
    ZPS_NWK_NLME_DCFM_NETWORK_DISCOVERY, /**< Use with ZPS_tsNwkNlmeCfmNetworkDiscovery */
    ZPS_NWK_NLME_DCFM_JOIN,              /**< Use with ZPS_tsNwkNlmeCfmJoin */
    ZPS_NWK_NLME_DCFM_START_ROUTER,      /**< Use with ZPS_tsNwkNlmeCfmStartRouter */
    ZPS_NWK_NLME_DCFM_DIRECT_JOIN,       /**< Use with ZPS_tsNwkNlmeCfmDirectJoin */
    ZPS_NWK_NLME_DCFM_PERMIT_JOINING,    /**< Use with ZPS_tsNwkNlmeCfmPermitJoining */
    ZPS_NWK_NLME_DCFM_NETWORK_FORMATION, /**< Use with ZPS_tsNwkNlmeCfmNetworkFormation */
    ZPS_NWK_NLME_DCFM_LEAVE,             /**< Use with ZPS_tsNwkNlmeCfmLeave */
    ZPS_NWK_NLME_DCFM_SYNC,              /**< Use with ZPS_tsNwkNlmeCfmSync */
    ZPS_NWK_NLME_DCFM_ROUTE_DISCOVERY,   /**< Use with ZPS_tsNwkNlmeCfmRouteDiscovery */
    ZPS_NWK_NLME_DCFM_ED_SCAN,           /**< Use with ZPS_tsNwkNlmeCfmEdScan */
    ZPS_NWK_NLME_DCFM_RESET,             /**< Use with ZPS_tsNwkNlmeCfmReset */
    ZPS_NWK_NLME_IND_JOIN,               /**< Use with ZPS_tsNwkNlmeIndJoin */
    ZPS_NWK_NLME_IND_LEAVE,              /**< Use with ZPS_tsNwkNlmeIndLeave */
    ZPS_NWK_NLME_IND_NWK_STATUS,         /**< Use with ZPS_tsNwkNlmeIndNwkStatus */
    ZPS_NWK_NLME_IND_DUTYCYCLE,          /**< Use with ZPS_tsNwkNlmeIndDutyCycle */
    ZPS_NWK_NLME_IND_ROUTE_RECORD,       /**< Use with ZPS_tsNwkNlmeCfmRouteRecord */
    ZPS_NWK_NLME_IND_FC_OVERFLOW,        /**< Use with ZPS_tsNwkNlmeCfmFCOverflow */
    ZPS_NWK_NLME_DCFM_ACTIVE_DISCOVERY,
    NUM_ZPS_NWK_NLME_DCFM_IND
} ZPS_teNwkNlmeDcfmIndType;

/**
 * @brief NLME Indication and Deferred Confirm parameter union
 *
 * Union of all the possible NLME indications and deferred confirmations,
 * including all the vendor-specific indications
 */
typedef union
{
    ZPS_tsNwkNlmeCfmNetworkDiscovery sDcfmNetworkDiscovery; /**< Network Discovery confirm */
    ZPS_tsNwkNlmeCfmJoin             sDcfmJoin;             /**< Join confirm */
    ZPS_tsNwkNlmeCfmStartRouter      sDcfmStartRouter;      /**< Start Router confirm */
    ZPS_tsNwkNlmeCfmDirectJoin       sDcfmDirectJoin;       /**< Direct Join confirm */
    ZPS_tsNwkNlmeCfmPermitJoining    sDcfmPermitJoining;    /**< Permit Joining confirm */
    ZPS_tsNwkNlmeCfmNetworkFormation sDcfmNetworkFormation; /**< Network Formation confirm */
    ZPS_tsNwkNlmeCfmLeave            sDcfmLeave;            /**< Leave confirm */
    ZPS_tsNwkNlmeCfmSync             sDcfmSync;             /**< Synchronisation confirm */
    ZPS_tsNwkNlmeCfmRouteDiscovery   sDcfmRouteDiscovery;   /**< Route Discovery confirm */
    ZPS_tsNwkNlmeCfmEdScan           sDcfmEdScan;           /**< ED Scan confirm */
    ZPS_tsNwkNlmeCfmReset            sDcfmReset;            /**< Reset confirm */
    ZPS_tsNwkNlmeIndJoin             sIndJoin;              /**< Join indication */
    ZPS_tsNwkNlmeIndLeave            sIndLeave;             /**< Leave indication */
    ZPS_tsNwkNlmeIndNwkStatus        sIndNwkStatus;         /**< Network status indication */
    ZPS_tsNwkNlmeIndDutyCycle        sIndDutyCycle;         /**< MAC Duty Cycle Indication */
    ZPS_tsNwkNlmeCfmRouteRecord      sCfmRouteRecord;       /**< Route Record Received confirm */
    ZPS_tsNwkNlmeCfmFCOverflow       sCfmFCOverflow;        /**< FC overflow */
} ZPS_tuNlmeDcfmIndParam;

/**
 * @brief NLME Indication
 *
 * The object passed to the registered Deferred Confirm/Indication callback.
 */
typedef struct
{
    uint8                  u8Type;          /**< Deferred Confirm/Indication type @sa ZPS_teNwkNlmeDcfmIndType */
    uint8                  u8ParamLength;   /**< Parameter length in following union */
    uint16                 u16Pad;          /**< To show padding octets */
    ZPS_tuNlmeDcfmIndParam uParam;          /**< Union of all possible Deferred Confirms/Indications */
} ZPS_tsNwkNlmeDcfmInd __attribute__ ((aligned(4)));

/* @} */

/**********************/
/**** NLDE Request ****/
/**********************/

/**
 * @defgroup g_zps_nwk_sap_nlde_req NLDE Request objects
 * @ingroup g_zps_nwk_sap_nlde
 *
 * These are passed in a call to ZPS_NWK_vHandleNldeReqRsp.
 * Confirms to a Request will either be passed back synchronously on the function return,
 * or a special 'deferred' confirm will come back asynchronously via the
 * Deferred Confirm/Indication callback.
 * Responses have no effective confirmation of sending as they are in response to
 * an Indication; this will be indicated in the synchronous Confirm passed back.
 *
 * @{
 */

/**
 * @brief Structure for NLDE-DATA.request
 *
 * Data transmit request. Use type ZPS_NWK_NLDE_REQ_DATA
 */
typedef struct
{
    uint16 u16NwkDstAddr;                         /**< Destinatation (final) address */
    uint8  u8DstAddrMode;                         /**< Destination address mode */
    uint8  u8Radius;                              /**< Radius (defaults to 2 * MaxDepth) */
    uint8  u8NonMemberRadius;                     /**< Non-member (of group) radius */
    uint8  u8DiscoverRoute;                       /**< Whether to discover a route */
    uint8  u8SecurityEnable;                      /**< Sec */
    uint8  u8Handle;                              /**< NHLE assigned handle */
    PDUM_thNPdu hNPdu;                            /**< Handle of NPDU */
} ZPS_tsNwkNldeReqData;

/* @} */

/**********************/
/**** NLDE Confirm ****/
/**********************/

/**
 * @defgroup g_zps_nwk_sap_nlde_cfm NLDE Confirm objects
 * @ingroup g_zps_nwk_sap_nlde
 *
 * These come back synchronously as a returned parameter in the Request/Response call.
 * They can also be deferred and asynchronously posted via the Deferred Confirm/Indication callback.
 *
 * @{
 */

/**
 * @brief Structure for NLDE-DATA.confirm
 *
 * Data transmit confirm. Use type ZPS_NWK_NLDE_CFM_DATA
 */
typedef struct
{
    uint8 u8Status;     /**< Status of request @sa ZPS_teNwkEnum */
    uint8 u8Handle;     /**< NHLE assigned handle */
} ZPS_tsNwkNldeCfmData;

/**
 * @brief Common structure for all confirms
 */
typedef struct
{
    uint8 u8Status; /**< Status is common to all confirms and is always the first entry */
} ZPS_tsNwkNldeCfmCommon;

/* @} */

/*************************/
/**** NLDE Indication ****/
/*************************/

/**
 * @defgroup g_zps_nwk_sap_nlde_ind NLDE Indication Objects
 * @ingroup g_zps_nwk_sap_nlde
 *
 * These are sent asynchronously via the registered Deferred Confirm/Indication callback
 *
 * @{
 */

/**
 * @brief Structure for NLDE-DATA.indication
 *
 * Data received indication. Uses type ZPS_NWK_NLDE_IND_DATA
 */
typedef struct
{
    uint16 u16NwkSrcAddr;                         /**< Destinatation (final) address */
    uint16 u16NwkDstAddr;                         /**< Destinatation (final) address */
    uint8  u8DstAddrMode;                         /**< Destination address mode */
    uint8  u8LinkQuality;                         /**< Sec */
    uint8  u8SecurityUse;                         /**< Sec */
    uint8  u8NwkSeqNum;                           /* NWK seq Num */
    bool_t bFramePending;                         /**<Frame pending bit set?*/
    PDUM_thNPdu hNPdu;
} ZPS_tsNwkNldeIndData;

/* @} */

/***********************/
/**** NLDE Response ****/
/***********************/

/**
 * @defgroup g_zps_nwk_sap_nlde_RSP NLDE Response objects
 * @ingroup g_zps_nwk_sap_nlde
 *
 * @note There are currently no specified NLDE Responses
 */


/*****************************************/
/**** NLDE Request/Response Interface ****/
/*****************************************/

/**
 * @defgroup g_zps_nwk_sap_nlde_req_rsp_if NLDE Request/Response interface
 * @ingroup g_zps_nwk_sap_nlde grp_zps_nwk_vs
 *
 * The interface for the client to issue an NLDE Request or Response
 * is via a function call to ZPS_vNwkHandleNldeReqRsp.
 * @li Request/Response parameters are passed in via psNldeReqRsp
 * @li Synchronous Confirm parameters are passed out via psNldeSyncCfm
 * @li Deferred Confirms are posted back asynchronously via the
 *     Deferred Confirm/Indication callback.
 * @note There are currently no NLDE Responses specified
 *
 * @{
 */

/**
 * @brief MAC NLDE Request/Response enumeration.
 *
 * Enumeration of MAC NLDE Request/Response
 * @note Must not exceed 256 entries
 */
typedef enum
{
    ZPS_NWK_NLDE_REQ_DATA = 0,  /**< Use with ZPS_tsNwkNldeReqData */
    NUM_ZPS_NWK_NLDE_REQ        /**> (endstop) */
} ZPS_teNwkNldeReqRspType;

/**
 * @brief NLDE Request/Response Parameter union
 *
 * Union of all the possible NLDE Requests and Responses
 * @note There are no Responses currently specified
 */
typedef union
{
    ZPS_tsNwkNldeReqData  sReqData; /**< Data request */
} ZPS_tuNldeReqRspParam;

/**
 * @brief NLDE Request/Response object
 *
 * The object passed to ZPS_vNwkHandleNldeReqRsp containing the request/response
 */
typedef struct
{
    uint8                 u8Type;        /**< Request type (@sa ZPS_teNwkNldeReqRspType) */
    uint8                 u8ParamLength; /**< Parameter length in following union */
    uint16                u16Pad;        /**< To show padding octets */
    ZPS_tuNldeReqRspParam uParam;        /**< Union of all possible Requests */
} ZPS_tsNwkNldeReqRsp;

/**
 * @brief Synchronous confirm status
 *
 * Indicates in the synchronous confirm whether:
 * @li The Request was processed with or without error
 * @li The confirm will be deferred and posted via the Deferred Confirm/Indication callback
 * @li It is a dummy confirm to a Response.
 * @note NB Must not exceed 256 entries
 */
typedef enum
{
    ZPS_NWK_NLDE_CFM_OK,       /**< Synchronous confirm without error */
    ZPS_NWK_NLDE_CFM_ERROR,    /**< Synchronous confirm with error; see u8Status field */
    ZPS_NWK_NLDE_CFM_DEFERRED, /**< Asynchronous deferred confirm will occur */
    NUM_ZPS_NWK_NLDE_CFM       /**< (endstop) */
} ZPS_teNwkNldeSyncCfmStatus;

/**
 * @brief NLDE Synchronous Confirm Parameter union
 *
 * Union of all the possible NLDE Synchronous Confirms
 */
typedef union
{
    ZPS_tsNwkNldeCfmCommon sCommon;  /**< Structure common to all confirms */
    ZPS_tsNwkNldeCfmData   sCfmData; /**< Data confirm */
} ZPS_tuNldeSyncCfmParam;

/**
 * @brief NLDE Synchronous Confirm
 *
 * The object returned by ZPS_vNwkHandleNldeReqRsp containing the synchronous confirm.
 * The confirm type is implied as corresponding to the request
 * @note All Confirms may also be sent asynchronously via the registered Deferred Confirm/Indication callback;
 * this is notified by returning ZPS_NWK_NLDE_CFM_DEFERRED.
 */
typedef struct
{
    uint8                  u8Status;      /**< Confirm status (@sa ZPS_teNwkNldeSyncCfmStatus) */
    uint8                  u8ParamLength; /**< Parameter length in following union */
    uint16                 u16Pad;        /**< To show padding octets */
    ZPS_tuNldeSyncCfmParam uParam;        /**< Union of all possible Confirms */
} ZPS_tsNwkNldeSyncCfm;

/* @} */

/****************************************************/
/**** NLDE Deferred Confirm/Indication Interface ****/
/****************************************************/

/**
 * @defgroup g_zps_nwk_sap_nlde_scfm_ind_if NLDE Deferred Confirm/Indication Interface
 * @ingroup g_zps_nwk_sap_nlde grp_zps_nwk_vs
 *
 * The interface for the client to receive an NLDE Deferred Confirm or Indication
 * is via a function callback to the function registered using ZPS_vNwkRegisterNldeDcfmIndCallbacks
 *
 * @{
 */

/**
 * @brief Deferred Confirm/Indication type
 *
 * Indicates the type of deferred confirm or indication
 * @note NB Must not exceed 256 entries
 */
typedef enum
{
    ZPS_NWK_NLDE_DCFM_DATA,
    ZPS_NWK_NLDE_IND_DATA,
    NUM_ZPS_NWK_NLDE_IND
} ZPS_teNwkNldeDcfmIndType;

/**
 * @brief NLDE Deferred Confirm/Indication Parameter union
 *
 * Union of all the possible NLDE Deferred Confirms or Indications
 */
typedef union
{
    ZPS_tsNwkNldeCfmData  sDcfmData; /**< Deferred transmit data confirm */
    ZPS_tsNwkNldeIndData  sIndData;  /**< Received data indication */
} ZPS_tuNldeDcfmIndParam;

/**
 * @brief NLDE Deferred Confirm/Indication
 *
 * The object passed in the NLDE Deferred Confirm/Indication callback
 */
typedef struct
{
    uint8                  u8Type;        /**< Indication type (@sa ZPS_teNwkNldeDcfmIndType) */
    uint8                  u8ParamLength; /**< Parameter length in following union */
    uint16                 u16Pad;        /**< To show padding octets */
    ZPS_tuNldeDcfmIndParam uParam;        /**< Union of all possible Indications */
} ZPS_tsNwkNldeDcfmInd;

/**
 * @brief Structure for inter pan .confirm
 *
 * Data transmit confirm. Use type ZPS_NWK_NLDE_CFM_DATA
 */
typedef struct
{
    uint8 u8Status;     /**< Status of request @sa ZPS_teNwkEnum */
    uint8 u8Handle;     /**< NHLE assigned handle */
} ZPS_tsNwkInterPanCfmData;


/**
 * @brief Structure for NLDE-DATA.indication
 *
 * Data received indication. Uses type ZPS_NWK_NLDE_IND_DATA
 */
typedef struct
{
    uint16 u16DstPan;                         /**<  */
    uint16 u16SrcPan;
    uint64 u64SrcAddr;
    uint8  u8DstAddrMode;
    uint8 u8SrcAddrMode;
    uint8  u8LinkQuality;                         /**< Sec */
    union {
        uint64 u64Addr;
        uint16 u16Addr;
     }uDstAddr;
     PDUM_thNPdu hNPdu;
} ZPS_tsNwkInterPanIndData;

/****************************************************/
/**** NLDE Deferred Confirm/Indication Interface ****/
/****************************************************/

/**
 * @defgroup g_zps_nwk_sap_nlde_scfm_ind_if Inter Pan Deferred Confirm/Indication Interface
 * @ingroup g_zps_nwk_sap_nlde grp_zps_nwk_vs
 *
 * The interface for the client to receive an Inter Pan Deferred Confirm or Indication
 * is via a function callback to the function registered using ZPS_vRegisterInterPanHandlers
 *
 * @{
 */

/**
 * @brief Deferred Confirm/Indication type
 *
 * Indicates the type of deferred confirm or indication
 * @note NB Must not exceed 256 entries
 */
typedef enum
{
    ZPS_NWK_INTERPAN_DCFM_DATA,
    ZPS_NWK_INTERPAN_IND_DATA,
    NUM_ZPS_NWK_INTERPAN_IND
} ZPS_teNwkInterPanDcfmIndType;

/**
 * @brief Inter Pam Deferred Confirm/Indication Parameter union
 *
 * Union of all the possible NLDE Deferred Confirms or Indications
 */
typedef union
{
    ZPS_tsNwkInterPanCfmData  sDcfmData; /**< Deferred transmit data confirm */
    ZPS_tsNwkInterPanIndData  sIndData;  /**< Received data indication */
} ZPS_tuInterPanDcfmIndParam;

/**
 * @brief Inter Pan Deferred Confirm/Indication
 *
 * The object passed in the NLDE Deferred Confirm/Indication callback
 */
typedef struct
{
    uint8                  u8Type;        /**< Indication type (@sa ZPS_teNwkNldeDcfmIndType) */
    uint8                  u8ParamLength; /**< Parameter length in following union */
    uint16                 u16Pad;        /**< To show padding octets */
    ZPS_tuInterPanDcfmIndParam uParam;        /**< Union of all possible Indications */
} ZPS_tsNwkInterPanDcfmInd;


/* @} */

/**
 * @defgroup g_zps_nwk_sap_generic Generic headers
 * @ingroup g_zps_nwk_sap
 *
 * Generic headers which abstract the parameter interfaces to the function calls.
 * The headers reflect the common structure at the head of the derived structures
 * for NLME/NLDE
 *
 * @{
 */

/**
 * @brief Generic Request/Response header
 *
 * Abstraction of the header used for all Requests
 * @note Must match with the first two fields of NLDE and NLME Requests
 */
typedef struct
{
    uint8 u8Type;        /**< Request type */
    uint8 u8ParamLength; /**< Parameter length */
} ZPS_tsNwkReqRspHdr;

/**
 * @brief Generic Synchronous Confirm header
 *
 * Abstraction of the header used for all Confirms
 * @note Must match with the first two fields of NLDE and NLME Confirms
 */
typedef struct
{
    uint8 u8Status;      /**< Confirm status */
    uint8 u8ParamLength; /**< Parameter length */
} ZPS_tsNwkSyncCfmHdr;

/**
 * @brief Generic Deferred Confirm/Indication header
 *
 * Abstraction of the header used for all Indications
 * @note Must match with the first two fields of NLDE and NLME Indications
 */
typedef struct
{
    uint8 u8Type;        /**< Indication type */
    uint8 u8ParamLength; /**< Parameter length */
} ZPS_tsNwkDcfmIndHdr __attribute__ ((aligned(4)));

/* @} */

/****************************/
/**** EXPORTED VARIABLES ****/
/****************************/

/****************************/
/**** EXPORTED FUNCTIONS ****/
/****************************/

PUBLIC void
ZPS_vNwkHandleNlmeReqRsp(void *pvNwk,
                         ZPS_tsNwkNlmeReqRsp *psNlmeReqRsp,
                         ZPS_tsNwkNlmeSyncCfm *psNlmeSyncCfm);

PUBLIC void
ZPS_vNwkHandleNldeReqRsp(void *pvNwk,
                         ZPS_tsNwkNldeReqRsp *psNldeReqRsp,
                         ZPS_tsNwkNldeSyncCfm *psNldeSyncCfm);

PUBLIC void
ZPS_vNwkRegisterNlmeDcfmIndCallbacks(void *pvNwk,
                                     ZPS_tsNwkDcfmIndHdr * (*prGetBufCB)(void *),
                                     void (*prPostCB)(void *, ZPS_tsNwkDcfmIndHdr *),
                                     void *pvParam);

PUBLIC void
ZPS_vNwkRegisterNldeDcfmIndCallbacks(void *pvNwk,
                                     ZPS_tsNwkDcfmIndHdr * (*prGetBufCB)(void *),
                                     void (*prPostCB)(void *, ZPS_tsNwkDcfmIndHdr *),
                                     void *pvParam);

PUBLIC uint8
ZPS_u8NwkCalcNldeReqOverhead(void *pvNwk,
                             uint16 u16NwkDstAddr);

PUBLIC void zps_vNwkSetZgpAlias(void* pvNwk,uint16 u16AliasShortAddress, uint8 u8AliasSeq, uint8 u8ApsFrameCounter);
PUBLIC void zps_vZgpDeviceActive(void *pvNwk,uint16 u16Address);
#ifdef __cplusplus
};
#endif

#endif /* _zps_nwk_sap_h_ */

/* End of file **************************************************************/
